package com.axc.gallery2.edit.overLay;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.graphics.Paint.Style;
import android.graphics.drawable.BitmapDrawable;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;

import com.axc.gallery2.R;
import com.axc.gallery2.edit.EditActivity;
import com.axc.gallery2.edit.effective.ToZoom;

/**
 * 设计思路： 双击上层图片，表示完成 onDown x,y = picx,picy 就可以继续移动图片
 * 
 * @author Carldhu go
 */
public class OverLayView extends View implements Runnable, IOverLaybaseMethod {

	// 确定画布与背景
	private Canvas mCanvas;
	private Bitmap mBitmap;
	public static Bitmap mBitmapSave;
	private Bitmap mBitmapDecorate;
	private Bitmap sourceBitmap;
	private Paint mPaint;
	Bitmap saveDecorate;
	// 上层图片坐标
	int miDTX = 120;
	int miDTY = 120;

	// 触摸坐标
	int tX = 0, tY = 0;

	// 1/2装饰图
	int picw, pich = 0;

	// 橡皮擦的坐标
	int earseX, earseY = 110;

	// 判断触摸点是否在上层装饰图片上
	boolean isInDecorateImg = false;
	// 判断是否首次创建
	boolean canShow = false;
	// 判断是否按下橡皮擦
	boolean canEarse = false;
	// 判断是否可以缩放
	boolean canZoom = false;
	// 判断是否可以旋转
	boolean canSpin = false;
	// 选择图标（圆）半径
	int radius;
	// 判断是否旋转过
	boolean haspin = false;
	// 判断图片是否已经被改变大小
	boolean haschange = false;

	// 引导提示图片位置的Guider
	Canvas guiderCanvas;
	Bitmap guiderBitmap;
	Paint guiderPaint;

	int drawShape = -1;

	// 橡皮擦内容
	Bitmap earseBitmap;
	Canvas earseCanvas;
	int earseSize = 20;
	int zX, zY = 0;

	// 重画guider
	int mx;
	int my;
	int nguiderWidth;
	int nguiderHeight;

	// 旋转触摸点
	float px, py = 0;

	Matrix matrix;
	// 记录角度
	float tangle = 0;
	// 记录拉伸后宽度
	int afterExtendWidth = 0;

	// 记录按的位置
	int mark = 0;

	OverLayAdapter adapter = new OverLayAdapter();

	public OverLayView(Context context, int w, int h) {
		super(context);
		// 高度大于宽度
		/**
		 * 获取图片
		 */
		mBitmap = BitmapFactory.decodeFile(EditActivity.imageFileNames);
		/*
		 * mBitmap = ((BitmapDrawable) getResources().getDrawable(
		 * OverLayActivity.imageID)).getBitmap();
		 */

		mBitmap = new ToZoom().ProcessImage(mBitmap, w, h);
		mBitmapSave = new ToZoom().ProcessImage(mBitmap, w, h);
		mPaint = new Paint();

		// 初始化一个对象
		createDecrateImg();

		// 确定背景
		mCanvas = new Canvas(mBitmapSave);
		new Thread(this).start();
	}

	public void createDecrateImg() {
		mBitmapDecorate = ((BitmapDrawable) getResources().getDrawable(
				R.drawable.weibo)).getBitmap();
		picw = mBitmapDecorate.getWidth() / 2;
		pich = mBitmapDecorate.getHeight() / 2;
	}

	/**
	 * 拉伸 所有图片都开始以最小的形式出现，按需要比例放大 创建上层装饰图片
	 * 
	 * @param size
	 *            比例
	 */
	public void createDecorateImg(int extendX, int extensY) {

		// 中心点
		int cx = miDTX - (guiderBitmap.getWidth() / 2) + radius
				- mBitmapDecorate.getWidth() / 2
				+ (guiderBitmap.getWidth() - (2 * radius)) / 2;

		int cy = miDTY - (guiderBitmap.getHeight() / 2) + radius
				- mBitmapDecorate.getHeight() / 2
				+ (guiderBitmap.getHeight() - (2 * radius)) / 2;

		/*
		 * int oldx = tX - (miDTX - (guiderBitmap.getWidth() / 2) + radius -
		 * mBitmapDecorate.getWidth() / 2 + (guiderBitmap .getWidth() - (2 *
		 * radius)) / 2); int oldy = tY - (miDTY - (guiderBitmap.getHeight() /
		 * 2) + radius - mBitmapDecorate.getHeight() / 2 + (guiderBitmap
		 * .getHeight() - (2 * radius)) / 2);
		 */
		// int centerDiastance = (int) Math.sqrt(oldx * oldx + oldy * oldy);

		// 触摸点
		/*
		 * int nx = zX - (miDTX - (guiderBitmap.getWidth() / 2) + radius -
		 * mBitmapDecorate.getWidth() / 2 + (guiderBitmap .getWidth() - (2 *
		 * radius)) / 2); int ny = zY - (miDTY - (guiderBitmap.getHeight() / 2)
		 * + radius - mBitmapDecorate.getHeight() / 2 + (guiderBitmap
		 * .getHeight() - (2 * radius)) / 2); int centerDiastance2 = (int)
		 * Math.sqrt(nx * nx + ny * ny);
		 * 
		 * 
		 * mBitmapDecorate = new ToZoom().ProcessImage(sourceBitmap,
		 * sourceBitmap .getWidth() + dis, sourceBitmap.getHeight() + dis);
		 * mBitmapDecorate = new ToZoom().ProcessImage(sourceBitmap,
		 * sourceBitmap .getWidth() + dis, sourceBitmap.getHeight() + dis); int
		 * dis = centerDiastance2 - centerDiastance;
		 */
		int extendWidth = 20;// 35;
		int extendHeight = 15;
		switch (mark) {
		case 1:
			extendWidth = (cx - extendX);
			extendHeight = (cy - extensY);
			break;
		case 2:
			extendWidth = (extendX - cx);
			extendHeight = (cy - extensY);
			break;
		case 3:
			extendWidth = (extendX - cx);
			extendHeight = (extensY - cy) - 15;
			break;
		case 4:
			extendWidth = (cx - extendX);
			extendHeight = (extensY - cy);
			break;
		default:
			break;
		}

		/**
		 * 图片放大缩小处理
		 */
		if (haspin == true) {
			matrix = new Matrix();
			matrix.setRotate(tangle);
			mBitmapDecorate = new ToZoom().ProcessImage(sourceBitmap,
					extendWidth, extendHeight);
			mBitmapDecorate = Bitmap.createBitmap(mBitmapDecorate, 0, 0,
					mBitmapDecorate.getWidth(), mBitmapDecorate.getHeight(),
					matrix, true);
		} else {
			mBitmapDecorate = new ToZoom().ProcessImage(sourceBitmap,
					extendWidth, extendHeight);
		}

		// 拉伸之后旋转
		saveDecorate = mBitmapDecorate;
	}

	/**
	 * 创建位置标记
	 * 
	 * @param w
	 *            要创建的图片宽度
	 * @param h
	 *            要创建的图片高度
	 */
	public void createGuider(int w, int h) {
		guiderPaint = new Paint();
		guiderPaint.setStrokeWidth(2);
		guiderPaint.setColor(Color.RED);
		// 控制外图的大小
		/*
		 * guiderBitmap = Bitmap.createBitmap(w+mBitmapDecorate.getWidth()*3,
		 * h+mBitmapDecorate.getHeight()*3, Config.ARGB_4444);
		 */
		guiderBitmap = Bitmap.createBitmap(w + 50, h + 50, Config.ARGB_4444);
		int width = guiderBitmap.getWidth();
		int height = guiderBitmap.getHeight();
		guiderCanvas = new Canvas(guiderBitmap);

		// 不论什么图片都自动适应
		// 统一图的1/5画方向
		int gwidth = 11;// width / 8;
		// 方向尾部为1/7
		int gend = 11;// width / 7;
		// 半径
		radius = 6;// gwidth / 2;

		// 倒退空间 为半径，为了显示选择的圆
		// 暂时先用画方向头的形式

		// 左上角
		guiderCanvas.drawLine(radius, radius, gwidth + radius, +radius,
				guiderPaint);
		guiderCanvas.drawLine(radius, radius, radius, gwidth + radius,
				guiderPaint);
		guiderCanvas.drawLine(radius, radius, gend + radius, gend + radius,
				guiderPaint);
		// 左下角
		guiderCanvas.drawLine(radius, height - radius, radius,
				(height - gwidth) - radius, guiderPaint);
		guiderCanvas.drawLine(radius, height - radius, gwidth + radius, height
				- radius, guiderPaint);
		guiderCanvas.drawLine(radius, height - radius, gend + radius,
				(height - gend) - radius, guiderPaint);
		// 右上角
		guiderCanvas.drawLine(width - radius, radius,
				(width - gwidth) - radius, radius, guiderPaint);
		guiderCanvas.drawLine(width - radius, radius, width - radius, gwidth
				+ radius, guiderPaint);
		guiderCanvas.drawLine(width - radius, radius, (width - gend) - radius,
				gend + radius, guiderPaint);
		// 右下角
		guiderCanvas.drawLine(width - radius, height - radius, width - radius,
				height - gwidth - radius, guiderPaint);
		guiderCanvas.drawLine(width - radius, height - radius, width - gwidth
				- radius, height - radius, guiderPaint);
		guiderCanvas.drawLine(width - radius, height - radius, width - gend
				- radius, height - gend - radius, guiderPaint);

		// up&middle
		guiderCanvas.drawCircle((float) (width / 2), radius, radius,
				guiderPaint);
		// right&middl
		guiderCanvas.drawCircle((float) (width - radius), (float) (height / 2),
				radius, guiderPaint);
		// bottom&middle
		guiderCanvas.drawCircle((float) (width / 2), (float) (height - radius),
				radius, guiderPaint);
		// left&middle
		guiderCanvas.drawCircle((float) (radius), (float) (height / 2), radius,
				guiderPaint);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		// 绘制背景图
		OverLayView.drawImage(canvas, mBitmapSave, 0, 0);
		// 触电在图范围内
		/*
		 * if (isInDecorateImg == true&&canEarse==false) { if (haschange==true)
		 * { AfterImgChange(canvas); } else { canvas.drawBitmap(mBitmapDecorate,
		 * miDTX - picw, miDTY - pich, mPaint); } }
		 */
		// 除了橡皮擦什么时候都显示
		if (canShow == true) {
			// 上层图片的移动
			if (canEarse == false) {
				if (canZoom) {
					canvas.drawBitmap(mBitmapDecorate, miDTX
							- (guiderBitmap.getWidth() / 2) + radius
							- mBitmapDecorate.getWidth() / 2
							+ (guiderBitmap.getWidth() - (2 * radius)) / 2,
							miDTY - (guiderBitmap.getHeight() / 2) + radius
									- mBitmapDecorate.getHeight() / 2
									+ (guiderBitmap.getHeight() - (2 * radius))
									/ 2, mPaint);
				} else {
					if (haschange == true) {
						// 重绘
						AfterImgChange(canvas);
					} else {
						/*
						 * canvas.drawBitmap(mBitmapDecorate, miDTX - picw,
						 * miDTY - pich, mPaint);
						 */
						canvas
								.drawBitmap(
										mBitmapDecorate,
										miDTX
												- (guiderBitmap.getWidth() / 2)
												+ radius
												- mBitmapDecorate.getWidth()
												/ 2
												+ (guiderBitmap.getWidth() - (2 * radius))
												/ 2,
										miDTY
												- (guiderBitmap.getHeight() / 2)
												+ radius
												- mBitmapDecorate.getHeight()
												/ 2
												+ (guiderBitmap.getHeight() - (2 * radius))
												/ 2, mPaint);
					}
				}
			}
			// 画标记 guider是画橡皮擦和位置标记的
			canvas.drawBitmap(guiderBitmap, miDTX
					- (guiderBitmap.getWidth() / 2), miDTY
					- (guiderBitmap.getHeight() / 2), mPaint);
		}
		if (canEarse == true) {
			canvas.drawBitmap(guiderBitmap, earseX - guiderBitmap.getWidth()
					/ 2, earseY - guiderBitmap.getHeight() / 2, mPaint);
		}

	}

	// 图片已经改变过 重绘位置
	public void AfterImgChange(Canvas canvas) {
		canvas.drawBitmap(mBitmapDecorate, miDTX
				- (guiderBitmap.getWidth() / 2) + radius
				- mBitmapDecorate.getWidth() / 2
				+ (guiderBitmap.getWidth() - (2 * radius)) / 2, miDTY
				- (guiderBitmap.getHeight() / 2) + radius
				- mBitmapDecorate.getHeight() / 2
				+ (guiderBitmap.getHeight() - (2 * radius)) / 2, mPaint);
	}

	// 触笔事件
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN:
			// 表示对象已经创建，创建后才可以判断位置
			if (canShow) {
				// 记录第一次按下的位置
				tX = (int) event.getX() - picw;
				tY = (int) event.getY() - pich;
				inRectangel(tX, tY, mBitmapDecorate);
				// 判断是否可以拉伸
				new DecorateImage(this).picZooms(mx, my, miDTX, miDTY,
						nguiderWidth, nguiderHeight, canZoom, haschange,
						guiderBitmap, radius, tX + picw, tY + pich);
				// 判断是否可以旋转
				new DecorateImage(this).ImgSpin(mx, my, miDTX, miDTY,
						nguiderWidth, nguiderHeight, guiderBitmap, radius, tX
								+ picw, tY + pich, canSpin, haschange);
			}
			// 判断如果橡皮擦可用（其他图片不空用）
			if (canEarse == true) {
				earseX = (int) event.getX();
				earseY = (int) event.getY();
			}
			break;
		case MotionEvent.ACTION_MOVE:
			// 在上层装饰图片范围内才可以移动图片
			if (isInDecorateImg && canEarse == false) {
				miDTX = (int) event.getX();
				miDTY = (int) event.getY();

				/*
				 * //new int centerX=miDTX - (guiderBitmap.getWidth() / 2) +
				 * radius - mBitmapDecorate.getWidth() / 2 +
				 * (guiderBitmap.getWidth() - (2 * radius)) / 2 +
				 * mBitmapDecorate.getWidth() / 2; int centerY=miDTY -
				 * (guiderBitmap.getHeight() / 2) + radius -
				 * mBitmapDecorate.getHeight() / 2 + (guiderBitmap.getHeight() -
				 * (2 * radius)) / 2 + mBitmapDecorate.getWidth() / 2;
				 * 
				 * miDTX=2*miDTX-centerX; miDTY=2*miDTY-centerY;
				 */

				this.CanZoom(false);
			}
			if (canZoom == true) {
				zX = (int) event.getX();
				zY = (int) event.getY();

				createDecorateImg(zX, zY);
				// 判断是否已经旋转过
				/*
				 * if(haspin){
				 * 
				 * }
				 */
				createGuider(mBitmapDecorate.getWidth(), mBitmapDecorate
						.getHeight());
			}
			if (canSpin == true) {
				px = event.getX();
				py = event.getY();
				mBitmapDecorate = ToSpin(miDTX - (guiderBitmap.getWidth() / 2)
						+ radius - mBitmapDecorate.getWidth() / 2
						+ (guiderBitmap.getWidth() - (2 * radius)) / 2
						+ mBitmapDecorate.getWidth() / 2, miDTY
						- (guiderBitmap.getHeight() / 2) + radius
						- mBitmapDecorate.getHeight() / 2
						+ (guiderBitmap.getHeight() - (2 * radius)) / 2
						+ mBitmapDecorate.getWidth() / 2, px, py);
				createGuider(mBitmapDecorate.getWidth(), mBitmapDecorate
						.getHeight());
			}
			if (canEarse == true) {
				earseX = (int) event.getX();
				earseY = (int) event.getY();
				createBgEarse(earseSize);
				mCanvas.drawBitmap(earseBitmap, earseX - earseBitmap.getWidth()
						/ 2, earseY - earseBitmap.getHeight() / 2, mPaint);
			}
			break;
		case MotionEvent.ACTION_UP:
			/*
			 * // 在上层装饰图片范围内才可以保存图片位置 if (isInDecorateImg && canEarse == false)
			 * { // 保存图片放后的位置 miDTX = (int) event.getX(); miDTY = (int)
			 * event.getY(); } if (canEarse == true) { earseX = (int)
			 * event.getX(); earseY = (int) event.getY(); }
			 */
			break;
		default:
			break;
		}
		return true;
	}

	// 判断是否在装饰图片上
	public void inRectangel(int x, int y, Bitmap top) {
		if (miDTX - picw - 0.5 * mBitmapDecorate.getWidth() < x
				&& x < miDTX - picw + 0.5 * top.getWidth()
				&& miDTY - pich - 0.5 * mBitmapDecorate.getHeight() < y
				&& y < miDTY - pich + 0.5 * top.getHeight()) {
			// 在图片范围内
			isInDecorateImg = true;
		} else {
			// 不在图片范围内
			isInDecorateImg = false;
		}
	}

	// 按键弹起事件
	public boolean onKeyUp(int keyCode, KeyEvent event) {
		return false;
	}

	// 多个键按下
	public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
		return true;
	}

	@Override
	public void run() {
		while (!Thread.currentThread().isInterrupted()) {
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				Thread.currentThread().interrupt();
			}
			// 使用postInvalidate可以直接在线程中更新界面
			postInvalidate();
		}
	}

	public static void drawImage(Canvas canvas, Bitmap bitmap, int x, int y) {
		// 绘制图像 将bitmap对象显示在坐标 x,y上
		canvas.drawBitmap(bitmap, x, y, null);
	}

	@Override
	public void bgEraser(int size) {
		// 创建橡皮擦
		// 创建时（位置指示图片）不可见
		canShow = false;
		canEarse = true;
		earseSize = size;
		canZoom = false;
		canSpin = false;
		createEarser(size);
		// createBgEarse(size);
		// 让图片对象消失
		miDTX = miDTY = -100;
	}

	/**
	 * 创建橡皮擦标志
	 * 
	 * @param w
	 */
	public void createEarser(int w) {
		guiderPaint = new Paint();
		guiderPaint.setStrokeWidth(2);
		guiderPaint.setStyle(Style.FILL);
		guiderPaint.setColor(Color.WHITE);
		guiderBitmap = Bitmap.createBitmap(w, 2 * w, Config.ARGB_4444);
		guiderCanvas = new Canvas(guiderBitmap);
		guiderCanvas.drawRect(0, 0, w, w / 4, guiderPaint);

		guiderPaint.setStyle(Style.FILL);
		guiderPaint.setStrokeWidth(5);
		guiderPaint.setColor(Color.BLUE);
		guiderCanvas.drawRect(0, w / 3, w, 2 * w, guiderPaint);
	}

	/**
	 * 创建背景橡皮擦
	 * 
	 * @param w
	 */
	public void createBgEarse(int w) {
		canShow = false;
		canEarse = true;
		try {
			earseBitmap = Bitmap.createBitmap(w, 2 * w, Config.RGB_565);
			Bitmap contentImg = Bitmap.createBitmap(mBitmap, earseX
					- guiderBitmap.getWidth() / 2, earseY
					- guiderBitmap.getHeight() / 2, w, w * 2);
			/*
			 * Bitmap contentImg = Bitmap.createBitmap(mBitmap, miDTX -
			 * (guiderBitmap.getWidth() / 2) + radius -
			 * mBitmapDecorate.getWidth() / 2 + (guiderBitmap.getWidth() - (2 *
			 * radius)) / 2-(mBitmapDecorate.getWidth()/2), miDTY -
			 * (guiderBitmap.getHeight() / 2) + radius -
			 * mBitmapDecorate.getHeight() / 2 + (guiderBitmap.getHeight() - (2
			 * * radius)) / 2-(mBitmapDecorate.getHeight()/2), w, w * 2);
			 */
			earseCanvas = new Canvas(earseBitmap);
			earseCanvas.drawBitmap(contentImg, 0, 0, mPaint);
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

	@Override
	public void enSure() {
		if (canShow && canEarse == false) {
			/*
			 * if (canZoom) { Log.w("change", "true"); mCanvas .drawBitmap(
			 * mBitmapDecorate, miDTX - (guiderBitmap.getWidth() / 2) + radius -
			 * mBitmapDecorate.getWidth() / 2 + (guiderBitmap.getWidth() - (2 *
			 * radius)) / 2, miDTY - (guiderBitmap.getHeight() / 2) + radius -
			 * mBitmapDecorate.getHeight() / 2 + (guiderBitmap.getHeight() - (2
			 * * radius)) / 2, mPaint); miDTX = miDTY = -10000; } else {
			 * mCanvas.drawBitmap(mBitmapDecorate, miDTX - picw, miDTY - pich,
			 * mPaint); // 让图片对象消失 miDTX = miDTY = -10000; }
			 */
			mCanvas.drawBitmap(mBitmapDecorate, miDTX
					- (guiderBitmap.getWidth() / 2) + radius
					- mBitmapDecorate.getWidth() / 2
					+ (guiderBitmap.getWidth() - (2 * radius)) / 2, miDTY
					- (guiderBitmap.getHeight() / 2) + radius
					- mBitmapDecorate.getHeight() / 2
					+ (guiderBitmap.getHeight() - (2 * radius)) / 2, mPaint);
			miDTX = miDTY = -10000;
		}
	}

	@Override
	public void setCandraw() {
		canShow = true;
		canEarse = false;
	}

	@Override
	/**
	 * 初始化上层自定义图片
	 */
	public void setTopImg(int bitmap, int sBitmap) {
		// 可见性
		haspin = false;
		canShow = true;
		haschange = false;
		// 再次调用createDecorate

		mBitmapDecorate = ((BitmapDrawable) getResources().getDrawable(bitmap))
				.getBitmap();
		// mBitmapDecorate=new ToZoom().ProcessImage(mBitmapDecorate, 30,30);
		sourceBitmap = ((BitmapDrawable) getResources().getDrawable(sBitmap))
				.getBitmap();
		picw = mBitmapDecorate.getWidth() / 2;
		pich = mBitmapDecorate.getHeight() / 2;
		miDTX = 200;
		miDTY = 200;
		createGuider(mBitmapDecorate.getWidth(), mBitmapDecorate.getHeight());
		saveDecorate = mBitmapDecorate;
		// postInvalidate();
	}

	@Override
	public void HasChangePen() {
		// 图案到橡皮擦的转变
	}

	@Override
	public void setPenHollowStyle() {
		// 空心
		mPaint.setStyle(Style.STROKE);
	}

	@Override
	public void setPenfillStyle() {
		// 实心
		mPaint.setStyle(Style.FILL);
	}

	/**
	 * 刷新图案
	 */
	public void FilterStyle() {
		switch (drawShape) {
		case 0:
			CircleShape();
			break;
		case 1:
			rectangleShape();
			break;
		case 2:
			trigonShape();
			break;
		}
	}

	/**
	 * * 旋转
	 * 
	 * @param px
	 *            环绕点x
	 * @param py
	 *            环绕点y
	 * @param cx
	 *            图片中心点x
	 * @param cy
	 *            图片中心点y
	 * @param tx
	 *            触摸点x
	 * @param ty
	 *            触摸点y
	 */
	public Bitmap ToSpin(int cx, int cy, float tx, float ty) {
		haspin = true;
		// 触摸点到圆心的距离
		float l = (float) Math.sqrt(Math.pow((float) (ty - cy), 2d)
				+ Math.pow((float) (tx - cx), 2d));
		float s = (float) (ty - cy);
		if (tx > cx) {
			matrix = new Matrix();
			matrix.setRotate(Tangle(s / l));
			tangle = Tangle(s / l);
		} else {
			matrix = new Matrix();
			matrix.setRotate(180 - Tangle(s / l));
			tangle = 180 - (Tangle(s / l));
		}

		// mCanvas.drawPoint(cx, cy, mPaint);
		/*
		 * // 获取图片对角的长度作为画布的最大宽度和高度 int maxLength = (int)
		 * Math.sqrt(saveDecorate.getWidth() saveDecorate.getWidth() +
		 * saveDecorate.getHeight() saveDecorate.getHeight()); Bitmap b1 =
		 * Bitmap.createBitmap(maxLength + 1, maxLength + 1, Config.ARGB_8888);
		 * Canvas c1 = new Canvas(b1); Matrix matrix = new Matrix(); //
		 * 先移动到中心再在中心旋转
		 * 
		 * c1.drawBitmap(saveDecorate, b1.getWidth() / 2 -
		 * saveDecorate.getWidth() / 2, b1.getHeight() / 2 -
		 * saveDecorate.getHeight() / 2, guiderPaint); // 绕中心旋转整个画布
		 * matrix.postRotate(Tangle(s/l), b1.getWidth() / 2, b1.getHeight() /
		 * 2); c1.drawBitmap(b1, matrix, guiderPaint);
		 * 
		 * Bitmap b2 = Bitmap.createBitmap(maxLength + 1, maxLength + 1,
		 * Config.ARGB_8888); Canvas c = new Canvas(b2); c.drawBitmap(b1, 0, 0,
		 * guiderPaint); mBitmapDecorate = b2; return mBitmapDecorate;
		 */
		/*
		 * Matrix matrix = new Matrix(); matrix.setRotate(Tangle(s/l));
		 */

		Bitmap bitmap = Bitmap.createBitmap(saveDecorate, 0, 0, saveDecorate
				.getWidth(), saveDecorate.getHeight(), matrix, true);
		// saveDecorate=bitmap;
		return bitmap;
	}

	/**
	 * 反正弦
	 * 
	 * @param tangle
	 * @return
	 */
	public float Tangle(float value) {
		return (float) (Math.asin(value) * (180 / Math.PI));
	}

	@Override
	public void setCancel() {
		// 让图片对象消失
		if (canEarse == true) {
			createBgEarse(earseSize);
		} else {
			miDTX = miDTY = -100;
		}

	}

	// 橡皮擦形状
	@Override
	public void CircleShape() {
		// TODO Auto-generated method stub

	}

	@Override
	public void rectangleShape() {
		// TODO Auto-generated method stub

	}

	@Override
	public void trigonShape() {
		// TODO Auto-generated method stub

	}

	@Override
	public void EarseSize(int size) {
		earseSize = size;
		createEarser(size);
		createBgEarse(size);
	}

	@Override
	public void CanZoom(boolean z) {
		// TODO Auto-generated method stub
		canZoom = z;
	}

	@Override
	public void HasChange(boolean c) {
		// TODO Auto-generated method stub
		haschange = c;
	}

	@Override
	public void CanSpin(boolean s) {
		// TODO Auto-generated method stub
		canSpin = s;
	}

	@Override
	public void Mark(int m) {
		// TODO Auto-generated method stub
		mark = m;
	}
}
